from django.shortcuts import render

# Create your views here.
from . import models
from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAuthenticated
from .serializers import UserCouponModelSerializer
import datetime
class CouponView(ListAPIView):

    permission_classes = [IsAuthenticated, ]
    # queryset = models.UserCoupon.objects.filter(is_show=True,is_deleted=False,is_use=False,user_id=request.user.id)
    serializer_class = UserCouponModelSerializer

    def get_queryset(self):

        now = datetime.datetime.now()

        queryset = models.UserCoupon.objects.filter(
            is_show=True,
            is_deleted=False,
            is_use=False,
            user_id=self.request.user.id,
            start_time__lte=now,

        )

        #<class 'django.db.models.query.QuerySet'>

        # print(type(queryset))
        # from django.db.models.query import QuerySet
        #
        #
        # for obj in queryset:
        #     timer = obj.coupon.timer
        #     end_time = obj.start_time + datetime.timedelta(days=timer)
        #     if now.timestamp() <= end_time.timestamp():
        #         pass

        return queryset



